package com.gwc.schedule.dao.impl;

import com.gwc.schedule.dao.BaseDao;
import com.gwc.schedule.dao.SysScheduleDao;
import com.gwc.schedule.pojo.SysSchedule;
import com.gwc.schedule.pojo.SysUser;

import java.util.List;

public class SysScheduleDaoImpl extends BaseDao implements SysScheduleDao {
    public int addSchedule(SysSchedule schedule){
        String sql = "insert into sys_schedule values(default,?,?,?)";
        int rows = baseUpdate(sql, schedule.getUid(), schedule.getTitle(), schedule.getCompleted());
        return rows;
    }

    @Override
    public List<SysSchedule> findAll() {
        String sql = "select sid, uid, title, completed from sys_schedule";
        List<SysSchedule> sysSchedules = baseQuery(SysSchedule.class, sql);
        return sysSchedules;
    }

    @Override
    public List<SysSchedule> findAllScheduleByUid(int uid) {
        String sql = "select sid,uid,title,completed from sys_schedule where uid=?";
        return baseQuery(SysSchedule.class, sql, uid);
    }

    @Override
    public Integer addScheduleByUid(int uid) {
        String sql = "insert into sys_schedule value(default,?,'请输入日程',0)";
        return baseUpdate(sql,uid);
    }

    @Override
    public Integer updateSchedule(SysSchedule sysSchedule) {
        String sql = "update sys_schedule set title=?,completed=? where sid=?";
//        System.out.println(sysSchedule.getTitle());
        return baseUpdate(sql, sysSchedule.getTitle(),sysSchedule.getCompleted(),sysSchedule.getSid());
    }

    @Override
    public Integer deleteSchedule(int sid) {
        String sql = "delete from sys_schedule where sid=?";
        return baseUpdate(sql,sid);
    }
}
